<template>
	<view class="content">
		<view class="book-list" v-if="bookList.length">
			<view class="book-item" v-for="(item, index) in bookList" :key="index">
				<view>
					<view class="date">{{ item.date }}</view>
					<view>
						<view class="time">时间：{{ item.time }}</view>
						<view class="name">姓名：{{ item.username }}</view>
						<view class="address">地址：{{ item.address }}</view>
					</view>
				</view>
				<view>
					<view :style="{ color: getState(item) }">{{ getStateText(item) }}</view>
					<view class="detail flex-center" @click="toDetail(item)">查看详情</view>
				</view>
			</view>
		</view>
		<view class="no-tip flex-center-col" v-if="!bookList.length">
			<image src='https://bile-1306178125.cos.ap-shanghai.myqcloud.com/static/teamwang/no/nobook.png'
				mode="widthFix" />
			<view class="tip">当前暂无预约</view>
		</view>
	</view>
</template>

<script>
import {
	mapState,
	mapActions
} from 'vuex';
import { bookState } from '../../utils/stateEnum';
export default {
	data() {
		return {
		}
	},
	computed: {
		...mapState({
			bookList: state => state.book.bookList // 确保这里引用正确
		}),
	},
	onLoad(options) {
		this.getBookList();
	},
	onShow() {
		this.getBookList();
	},
	methods: {
		...mapActions(['getBookList',]),
		toDetail(item) {
			uni.navigateTo({
				url: '/packageA/bookDetail/bookDetail?bookId=' + item.id,
			});
		},
		getStateText(item) {
			switch (item?.status) {
				case bookState.NOUSE:
					return '待使用'
				case bookState.VERIFIED:
					return '已核销'
				case bookState.EXPIRED:
					return '已过期'
				case bookState.CANCELLED:
					return '已取消'
			}
		},
		getState(item) {
			switch (item?.status) {
				case bookState.NOUSE:
					return '#019E01'
				case bookState.VERIFIED:
					return '#666666'
				case bookState.EXPIRED:
					return '#D0021B'
				case bookState.CANCELLED:
					return '#D0021B'
			}
		}
	}
}
</script>

<style lang="scss" scoped>
.book-list {
	width: 100%;
	max-height: 100%;
	overflow-y: auto;
}

.book-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 0.3px solid $tip2-color;
	padding: 13px 25px;

	&:last-child {
		margin-bottom: 40px;
	}

	>view {
		height: 100px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-start;
		font-size: 12px;

		&:nth-child(2) {
			justify-content: space-between;
			align-items: flex-end;
		}

		.date {
			font-size: 16px;
			font-weight: 600;
			letter-spacing: 0.8px;
		}

		.name,
		.time,
		.address {
			letter-spacing: 0.8px;
			margin-top: 8px;
		}

		.detail {
			background: $primary-color;
			width: 88px;
			height: 28px;
			font-size: 12px;
			color: #FFFFFF;
		}
	}
}

.no-tip {
	width: 100%;
	height: 80%;

	image {
		width: 30%;
	}

	.tip {
		font-weight: 500;
		font-size: 14px;
		color: #C9C9C9;
		letter-spacing: 1px;
		margin-top: 18px;
	}
}
</style>
